home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 4 / MacMania 4.toast / / Tools&Utilities / MathPad 2.4 / Examples / projectile < prev    next >
Text File  |  1995-04-29  |  921b  |  35 lines

  1. --This example simulates a projectile with air friction proportional to its velocity. Upper case variables are {x,y} vectors. See example "falling" for an example in 1 dimension.
  2.  
  3. -- initial conditions
  4. init = V:={2,50},  -- velocity (mostly upward)
  5.        P:={0,0},   -- position
  6.        t:=0
  7.  
  8. stepto(stop) = init when stop=0,
  9.              (V:=V+A*dt,
  10.               P:=P+V*dt,
  11.               t:=t+dt) while t<stop
  12.  
  13. A=F/m
  14. Fgravity = {0,-m*g}
  15. Fdrag = -k*V
  16. F=Fgravity+Fdrag
  17.  
  18. g=9.8       -- accelleration due to gravity
  19. k=0         -- friction coefficient
  20. m=300       -- mass of object
  21. dt=.1       -- time step for simulation
  22.  
  23. Position(t1) = stepto(t1),P
  24.  
  25. -- parametric plot of position for t=0 to 10 -- {x,y} plot runs X from 0 to 1. Create new variable "tn" that runs 0 to tmax.
  26. tmax=10
  27. tn=X*tmax  
  28.  
  29. Ymin=0; Ymax=130;  Xmin=0; Xmax=20
  30.  
  31. plot Position(tn)  -- no friction
  32.  
  33. label k:=20:;      -- with friction
  34. plot Position(tn)
  35.